#include "Int.h"
#include <iostream>
using namespace std;

Int::Int(int n) : num(n) {

}

Int::Int(const Int &i) {
    this->num = i.num;
}

Int operator+(const Int& n1, const Int& n2) {
    return Int(n1.num + n2.num);
}

Int operator-(const Int& n1, const Int& n2) {
    return Int(n1.num - n2.num);
}

Int operator*(const Int& n1, const Int& n2) {
    return Int(n1.num * n2.num);
}

Int operator/(const Int& n1, const Int& n2) {
    return Int(n1.num / n2.num);
}

Int& Int::operator=(const Int& n) {
    if (this != &n) {
        this->num = n.num;
    }
	return *this;
}

Int& Int::operator+=(const Int &n) {
    this->num += this->num + n.num;
    return *this;
}

Int& Int::operator-=(const Int &n) {
    this->num -= this->num + n.num;
    return *this;
}

Int& Int::operator*=(const Int &n) {
    this->num *= this->num + n.num;
    return *this;
}

Int& Int::operator/=(const Int &n) {
    this->num /= this->num + n.num;
    return *this;
}

    //关系运算符
bool operator<(const Int& n1, const Int& n2) {
    return n1.num < n2.num;
}

bool operator>(const Int& n1, const Int& n2) {
    return n1.num > n2.num;
}

bool operator==(const Int& n1, const Int& n2) {
    return n1.num == n2.num;
}
    //自增自减
Int& Int::operator++() {
    this->num++;
    return *this;
}

Int Int::operator++(int) {
    Int n(*this);
    this->num++;
    return n;
}

Int& Int::operator--() {
    this->num--;
    return *this;
}
Int Int::operator--(int) {
    Int n(*this);
    this->num--;
    return n;
}
    //流插入和流提取运算符函数
ostream& operator<<(ostream& out, const Int& n) {
    out << n.num;
    return out;
}

istream& operator>>(istream& in, Int& n) {
    string str;
    in >> str;
    for (int i = 0; i < str.size(); i++) {
        int t = str.at(i) - '0';
        if (!(t >= 0 && t <= 9)) {
            break;
        }
        n.num = n.num * 10 + t;
    }
    return in;
}